package com.google.code.swingonfire.showcase.component.foldable;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;

import javax.swing.JComponent;

import com.google.code.swingonfire.utility.Colors;

public class CheckerboardComponent extends JComponent
{

    private static final long serialVersionUID = -6434991765358126344L;

    public CheckerboardComponent(Color background)
    {
        super();

        if (background != null)
        {
            setBackground(background);
        }
        
        setPreferredSize(new Dimension(128, 128));
    }

    @Override
    public void paint(Graphics g)
    {
        int size = 16;
        int width = getWidth();
        int height = getHeight();

        Color colorA = getBackground();
        Color colorB = Colors.darker(colorA, 0.25);

        for (int y = 0; y < height; y += size)
        {
            for (int x = 0; x < width; x += size)
            {
                if ((((x / size) + (y / size)) % 2) == 0)
                {
                    g.setColor(colorA);
                }
                else
                {
                    g.setColor(colorB);
                }

                g.fillRect(x, y, size, size);
            }
        }
    }

}
